package com.ncs.stm.helper;

import com.google.gson.Gson;
import com.ncs.stm.entity.Tip;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.List;


public class HttpHelper {

    /**
     *
     * @param url
     * @return
     */
    public static String getContentByGet(String url){
        HttpClient client = new DefaultHttpClient();
        try {
            HttpResponse response = client.execute(new HttpGet(url));
            String str = EntityUtils.toString(response.getEntity());
            return str;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * @param url
     * @return
     */
    public static Object getContentByGetDemo(String url){
        String jsonStr = "{\"id\":\"3a065951-bef8-4c01-9dba-cc22001512bd\",\"context\":\"题目2\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"}";
        Gson gson = new Gson();
        Tip tip = gson.fromJson(jsonStr, Tip.class);
        return tip;
    }

    public static List getContentListByGetDemo(String url,Class clazz){
        String jsonArrayStr = "[{\"id\":\"3a065951-bef8-4c01-9dba-cc22001512bd\",\"context\":\"题目2\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"ea7afe1c-29ed-4311-a4c1-cdfe14c47ad2\",\"context\":\"题目4\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"506023dd-968f-4e03-b998-e34c12c0c666\",\"context\":\"题目6\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"11d56878-7c2d-4856-9b77-650290e12efb\",\"context\":\"题目7\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"2b9334e6-3a4e-4ac8-9fa6-e19e909c7845\",\"context\":\"题目8\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"d65bf8d3-47af-4bce-a40f-5b7ed886da57\",\"context\":\"题目9\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"85e055eb-d6f0-4030-8140-d6fd56d3925b\",\"context\":\"题目10\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"edea0efd-0e71-4e65-b679-a1829155520a\",\"context\":\"题目11\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"063b3922-d8a4-4808-937a-8393d872461b\",\"context\":\"题目12\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"5ad0fa77-7188-4721-98e7-c33bf3f0125f\",\"context\":\"题目13\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"a6a49d78-d2d2-4e5c-b92d-1eb2fab04995\",\"context\":\"题目14\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"b341c014-ba4d-4383-803a-c7ab9981ad66\",\"context\":\"题目15\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"0aeb2dd9-7d76-4ee7-9d88-9e7e72f53983\",\"context\":\"题目16\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"7de57aff-18bf-4eb7-b94f-835b811b9e52\",\"context\":\"题目17\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"c7918f77-341d-41a7-842b-d8442fbdae76\",\"context\":\"题目18\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"52393446-b92f-46a6-a156-7bf587c50302\",\"context\":\"题目19\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"c014dd20-0185-4273-86a3-5b1cc2e00f9d\",\"context\":\"题目20\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"b8fac46c-95d3-4cd9-a5da-d6eef98be854\",\"context\":\"题目21\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"16daf587-7639-4f3e-895d-be6fe346656e\",\"context\":\"题目22\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"0cb847e9-74d5-4f77-963d-73e83df2ee40\",\"context\":\"题目23\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"7dc79000-d4fb-4511-b2c1-af9630ca637d\",\"context\":\"题目24\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"80d79ac3-47a3-4ee2-a83e-32e3fbac9919\",\"context\":\"题目25\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"c723b493-7a40-4347-b0c8-849c0a1fe02e\",\"context\":\"题目26\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"562d3086-d7a1-4768-b1f0-bdb5cd1f3a04\",\"context\":\"题目27\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"496999f9-2e14-42bf-8b1e-8840c5c988be\",\"context\":\"题目28\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"6af7b6b9-7568-4d5e-92a8-e3de71bb7014\",\"context\":\"题目29\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"0824ceb8-67a4-4169-85ac-63a8f2ecac07\",\"context\":\"题目30\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"0a60e2f4-597d-43c4-b32a-49128b15ea08\",\"context\":\"题目31\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"b1b318e0-c038-46de-a502-9b00c98e1ddd\",\"context\":\"题目32\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"82d63408-914b-4aeb-a4de-3dace77c4898\",\"context\":\"题目33\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"810314ce-0b01-4d81-b6f0-a052d3dcf7ad\",\"context\":\"题目34\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"8672e895-6379-4448-8154-7927d6c9d2c8\",\"context\":\"题目35\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"0192c177-27cf-4f87-aab6-3a4ff76bee23\",\"context\":\"题目36\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"2ca5abd6-89fe-4be3-bfc6-460de14df718\",\"context\":\"题目37\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"707f3d99-b1af-4a23-bbd1-8a1196a9896b\",\"context\":\"题目38\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"985e3b2d-c9a7-43b8-8512-46e9903fc2e7\",\"context\":\"题目39\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"7d5abd3b-74cd-40a3-9963-e32267c148ad\",\"context\":\"题目40\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"9145a397-851c-4699-a6b4-1a9cbf0d42f7\",\"context\":\"题目41\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"1bb365d5-1d29-478d-aa91-28856c7cc3ee\",\"context\":\"题目42\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"57c3fbac-819d-4530-882f-0eba162175d7\",\"context\":\"题目43\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"bbcacee3-f741-4474-a0f6-abcd598d3479\",\"context\":\"题目44\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"fb6ece9e-8834-43f2-83d7-352bcf34beed\",\"context\":\"题目45\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"},{\"id\":\"763be586-6db4-46d3-bea4-cfe6c87f5d2b\",\"context\":\"题目46\",\"count\":\"0\",\"rowId\":\"0\",\"columnId\":\"0\"}]";
        List list = JsonHelper.fromJsonArray(jsonArrayStr,clazz);
        return list;
    }

    public static List getCategoryListByGetDemo(String url,Class clazz){
        String jsonArrayStr = "[{\"id\":\"d2f04a84-f6e1-4b27-8d25-42f92b495d3d\",\"context\":\"与我的价值观相反\",\"count\":\"2\",\"rowid\":\"0\",\"columnid\":\"0\"},{\"id\":\"652556be-9dd6-4eb7-82eb-4e30638ae62c\",\"context\":\"很不重要\",\"count\":\"3\",\"rowid\":\"0\",\"columnid\":\"1\"},{\"id\":\"f8306bfc-3f8f-44f7-94df-616a56827868\",\"context\":\"不重要\",\"count\":\"5\",\"rowid\":\"0\",\"columnid\":\"2\"},{\"id\":\"5b31214b-d3f8-4f48-bbae-88f3416aa690\",\"context\":\"不太重要\",\"count\":\"8\",\"rowid\":\"0\",\"columnid\":\"3\"},{\"id\":\"028dfc1a-4ab5-46a8-9f13-2cd65c1e312f\",\"context\":\"重要\",\"count\":\"10\",\"rowid\":\"0\",\"columnid\":\"4\"},{\"id\":\"215bad01-1431-4383-bb43-4c4cb120a6d7\",\"context\":\"有点重要\",\"count\":\"8\",\"rowid\":\"0\",\"columnid\":\"5\"},{\"id\":\"41c138f9-3280-45c6-8535-e66e0ce1fbd8\",\"context\":\"比较重要\",\"count\":\"5\",\"rowid\":\"0\",\"columnid\":\"6\"},{\"id\":\"b9f757fc-cc32-4d7b-b71d-e49d1381a1cc\",\"context\":\"非常重要\",\"count\":\"3\",\"rowid\":\"0\",\"columnid\":\"7\"},{\"id\":\"32ff4390-8cea-4a4b-9fc1-cd5543d02193\",\"context\":\"极端重要\",\"count\":\"2\",\"rowid\":\"0\",\"columnid\":\"8\"}]";
        List list = JsonHelper.fromJsonArray(jsonArrayStr,clazz);
        return list;
    }

    public static <T> T loginByGetDemo(String url,Class<T> clazz){
        String jsonStr = "{\"username\":\"zhangsan\",\"phonenumber\":\"17777777777\",\"address\":\"London\"}";
        Gson gson = new Gson();
        return gson.fromJson(jsonStr,clazz);
    }

}
